package jiazhong.hfl20250308;

import java.util.ArrayList;

//5.有⼀个存放边长的集合，计算集合中的边长能够组成多少种不同的三角形
public class Triangle {

    public static int countTriangle(int[] edges) {
        int count = 0;
        for (int i = 0; i < edges.length; i++) {
            for (int j = i + 1; j < edges.length; j++) {
                for (int k = j + 1; k < edges.length; k++) {
                    if (edges[i] + edges[j] > edges[k] && edges[j] + edges[k] > edges[i] && edges[i] + edges[k] > edges[j]) {//判断是否能组成三角形条件
                        count++;
                    }
                }
            }
        }
        return count;
    }

    public static void main(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
        for (int i = 1; i <= 10; i++) {
            list.add((int) (Math.random() * 10 + 1));
        }
//        list.add(3);
//        list.add(4);
//        list.add(5);
//        list.add(10);
        System.out.println(list);
        int[] edges = new int[list.size()];
        for (int i = 0; i < list.size(); i++) {
            edges[i] = list.get(i);
        }
        System.out.println(countTriangle(edges));
    }
}
